import { InputQuestion, QuestionBase, TimeQuestion, SelectQuestion, RadioQuestion, TextQuestion, CustomTableQuestion, UploadQuestion } from '@/components/public-template';
import { Api as ApiSystem } from '@/config/api/system';
import { Api as ApiResource } from '@/config/api/resourceFileInfo';
import { regExp } from '@/utils/regExp';


class IndexService {
  getQuestions(showType) {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'billCode',
        label: '单据编号'
      }),
      new TextQuestion({
        key: 'creator',
        hide: true,
        value: null
      }),
      new TextQuestion({
        key: 'creatorName',
        label: '创建人',
        value: null
      }),
      new TextQuestion({
        key: 'department',
        hide: true,
        value: null
      }),
      new TextQuestion({
        key: 'departmentName',
        label: '创建部门',
        value: null
      }),
      new TextQuestion({
        key: 'createdTime',
        label: '创建时间',
        value: null
      }),
      new TextQuestion({
        key: 'expirationReminder',
        label: '到期提醒时间',
        value: null
      }),
      ['ADD', 'EDIT'].includes(showType)
        ? new InputQuestion({
            key: 'reason',
            label: '销毁原因',
            required: true,
            prompt: '请输入',
            value: null
          })
        : new TextQuestion({
            key: 'reason',
            label: '销毁原因',
            value: null
          }),
      ['ADD', 'EDIT'].includes(showType)
        ? new InputQuestion({
            key: 'remark',
            label: '备注',
            value: null
          })
        : new TextQuestion({
            key: 'remark',
            label: '备注',
            value: null
          })
    ];
    return questions;
  }
  getDestroyListQuestions(showType) {
    const questions: QuestionBase<any>[] = [
      new CustomTableQuestion({
        key: 'fileList',
        value: [],
        state: {
          grid: 24,
          fullLine: true,
          isAdd: ['ADD', 'EDIT'].includes(showType),
          hideBorder: true,
          columns: [
            {
              title: '序号',
              type: 'index'
            },
            {
              title: '文件名称',
              key: 'name',
              type: ['ADD', 'EDIT'].includes(showType) ? 'select' : null,
              required: ['ADD', 'EDIT'].includes(showType),
              prompt: '请选择'
            },
            {
              title: '文件编码',
              key: 'code'
            },
            {
              title: '文件号',
              key: 'fileCode'
            },
            {
              title: '文件格式',
              key: 'suffix'
            },
            {
              title: '文件页数',
              key: 'filePages'
            },
            {
              title: '档案编码',
              key: 'filesBoxCode'
            },
            {
              title: '档案类型',
              key: 'filesTypeName'
            },
            {
              title: '存放地点',
              key: 'storageLocationCode'
            },
            {
              title: '档案盒编码',
              key: 'boxCode'
            },
            {
              title: '档案盒名称',
              key: 'boxName'
            },
            {
              title: '载体形式',
              key: 'type',
              type: 'dictionary',
              state: {
                filterName: 'CARRIER_TYPE'
              }
            },
            {
              title: '操作',
              type: 'operation',
              handle: [
                {
                  type: 'local',
                  text: '预览',
                  class: 'text-primary',
                  state: {
                    name: 'LOCAL_PREVIEW'
                  }
                },
                {
                  type: 'delete',
                  text: ['ADD', 'EDIT'].includes(showType) ? '删除' : null,
                  class: 'text-primary',
                  url: '/url',
                  params: [{ id: 'id' }],
                  state: {}
                }
              ]
            }
          ]
        }
      })
    ];
    return questions;
  }
  getTeamQuestions(showType) {
    const questions: QuestionBase<any>[] = [
      showType == 'AUDIT'
        ? new SelectQuestion({
            key: 'peopleIds',
            label: '档案销毁鉴定小组',
            value: [],
            required: true,
            prompt: '请选择',
            state: {
              url: ApiSystem.subjectListSimple,
              protType: 'post',
              nameKey: 'nickName',
              nameValue: 'id',
              mode: 'multiple',
              showSearch: true,
              optionFilterProp: 'label'
            }
          })
        : new TextQuestion({
            key: 'peopleName',
            label: '档案销毁鉴定小组',
            value: []
          })
    ];
    return questions;
  }
  getConfirmQuestions(showType) {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'destoryQty',
        label: '档案销毁份数',
        type: 'number',
        reg: regExp.positiveInteger,
        required: true,
        prompt: '请输入',
        value: null
      }),
      new TimeQuestion({
        key: 'actualTime',
        label: '实际销毁时间',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'alone',
        state: {
          showTime: true,
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss'
        }
      }),
      new InputQuestion({
        key: 'causeDescription',
        label: '原因说明',
        type: 'textarea',
        value: null,
        reg: regExp.len100,
        prompt: '长度不可超过100个字符'
      }),
      new InputQuestion({
        key: 'reviewer',
        label: '销毁复核人',
        value: null,
        required: true,
        prompt: '请确认',
        type: 'slot',
        state: {
          slotName: 'reviewer',
          grid: 24
        }
      })
    ];
    const viewQuestions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'destoryQty',
        label: '档案销毁份数',
        value: null
      }),
      new TextQuestion({
        key: 'actualTime',
        label: '实际销毁时间',
        value: null
      }),
      new TextQuestion({
        key: 'causeDescription',
        label: '原因说明',
        value: null
      }),
      new TextQuestion({
        key: 'reviewer',
        label: '销毁复核人',
        type: 'slot',
        value: null,
        state: {
          slotName: 'reviewer'
        }
      }),
      new TextQuestion({
        key: 'reviewer',
        label: '销毁复核人',
        value: null,
        hide: true
      }),
      new TextQuestion({
        key: 'confirmBill',
        label: '销毁确认单',
        value: null,
        type: 'slot',
        state: {
          slotName: 'confirmBill'
        }
      })
    ];
    return showType == 'CONFIRM' ? questions : viewQuestions;
  }
  getSignQuestions(phone) {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'account',
        label: '账号',
        required: true,
        prompt: '请输入',
        value: phone,
        defaultValue: phone
      }),
      new InputQuestion({
        key: 'password',
        label: '密码',
        type: 'password',
        required: true,
        prompt: '请选择',
        value: null
      })
    ];
    return questions;
  }
  getPreviewQuestions() {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'destoryQty',
        label: '档案销毁份数',
        value: null
      }),
      new TextQuestion({
        key: 'actualTime',
        label: '实际销毁时间',
        value: null
      }),
      new TextQuestion({
        key: 'causeDescription',
        label: '原因说明',
        value: null
      }),
      new UploadQuestion({
        key: 'reviewer',
        label: '销毁复核人',
        value: null,
        disabled: true,
        state: {
          isImage: true,
          viewUrl: ApiResource.resourceViewFile
        }
      })
    ];
    return questions;
  }
  getCommentQuestions() {
    const questions: QuestionBase<any>[] = [
      new RadioQuestion({
        key: 'applyResult',
        label: '意见',
        required: true,
        prompt: '请选择',
        value: 1,
        options: [
          {
            label: '通过',
            value: 1
          },
          {
            label: '驳回',
            value: 2
          }
        ]
      }),
      new InputQuestion({
        key: 'remark',
        label: '备注',
        value: null
      })
    ];
    return questions;
  }
}

export default new IndexService();
